﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using web.httpfetch;
using System.Text.RegularExpressions;

namespace HtmlParser
{
    /// <summary>
    /// Summary description for htmlParser
    /// </summary>
    [TestClass]
    public class htmlParser
    {
        public htmlParser()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void TestMethod1()
        {
            //
            // TODO: Add test logic	here
            //
        }

        [TestMethod]
        public void StringHashTest()
        {
            String a="D:\\git\\httpfetch\\httpfetch\\Program.cs(25,25):";
            Console.WriteLine(a);
        }

        [TestMethod]
        public void MoveToNextTagTest()
        {
            String mainText = "<html>\n<head>abc</head><body><p>abc</p></body></html>";
            int start = HtmlParserHelper.moveToNextTagStart(mainText, 1);
            Assert.AreEqual(7, start);

            start = HtmlParserHelper.moveToThisTagEnd(mainText, 1);
            Assert.AreEqual(5, start);
        }
        [TestMethod]
        public void SkipBlanksTest()
        {
            String mainText = "     5";
            int skipNumber = HtmlParserHelper.skipBlanks(mainText, 0);
            Assert.AreEqual(skipNumber, 5);
        }

        [TestMethod]
        public void GetPropertyTest()
        {
            String mainText = "<a href = \".\">adsf</a>";
            String name = HtmlParserHelper.getProperty(mainText, 0, "href");
            Assert.AreEqual(".", name);

            mainText = "<a href = \"http://www.google.com.au\">adsf</a>";
            name = HtmlParserHelper.getProperty(mainText, 0, "href");
            Assert.AreEqual("http://www.google.com.au", name);

            mainText = "<meta http-equiv=\"content-type\" content=\"text/html;charset=UTF-8\" />";
            name = HtmlParserHelper.getProperty(mainText, 0, "charset");
            Assert.AreEqual("UTF-8", name);
        }

        [TestMethod]
        public void LinkTagTest()
        {

        }

        [TestMethod]
        public void HtmlNodeTest()
        {
            //String mainText = "<html>\n<head>abc</head><body><p>abc asdf<strong>This is strong</strong>abcdef</p></body></html>";

            //int i = 0;
            //while (i < mainText.Length)
            //{
            //    //Get Tag (start end)
            //    //Push to Stack
            //    //Get pair Tag (start end)
            //    //if GetTopStack() Match
            //    //pop up 
            //    //Tag.parent = GetTopStack();
            //    //Tag.Save(TagName,start1,end1,start1,end1);
            //}
        }

        /// <summary>
        /// 
        /// </summary>
        [TestMethod]
        public void DeleteAllTagInString()
        {
            string main = "<p>asdf<strong>asdf</strong>asdfkaqq123</p>";

        }

        [TestMethod]
        public void RegexTest()
        {
            Regex r = new Regex("^ *$");
            string targe = "   abc";
            Assert.AreEqual(true, r.IsMatch(targe));
        }

    }
}
